<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>6、用 canvas 让图片绕自己转。</title>
</head>

<canvas width="1000px" height="1000px" style="border: 1px solid red;"">
  <img src=" https://img-home.csdnimg.cn/images/20201124032511.png" alt="" style="display: no
  ;">
</canvas>

<body>
  <script>
    let canvas = document.querySelector('canvas')
    let canvat = canvas.getContext('2d')
    let obj = {
      x: 0,
      y: 0,
      width: 400,
      height: 400
    }
    let img = document.querySelector('img')
    function rotes() {
      //画布的中心位置
      canvat.translate((obj.x + (obj.width / 2)), (obj.y + (obj.height / 2)))
      //旋转
      canvat.rotate(Math.PI / 180);
      //再回到起始位置
      canvat.translate(-(obj.x + (obj.width / 2)), -(obj.y + (obj.height / 2)))
      canvat.drawImage(img, 0, 0, 400, 400)
    }
    setInterval(rotes, 10)
  </script>
</body>

</html>